/*
 * @Author: tanying
 * @Date: 2024-04-25 13:52:09
 * @LastEditTime: 2024-04-26 15:47:33
 * @LastEditors: tanying
 * @FilePath: \vue-three\src\components\model.js
 * @Description: 
 */
// 引入Three.js
import * as THREE from 'three';
// 引入gltf模型加载库GLTFLoader.js
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';


const loader = new GLTFLoader(); 

const model = new THREE.Group();


const gltf = await loader.loadAsync("./model/机器人.glb");
const player = gltf.scene;//玩家角色模型
model.add(player)

//包含关键帧动画的模型作为参数创建一个播放器
const mixer = new THREE.AnimationMixer(player);
console.log('gltf.animations', gltf.animations);
// gltf.animations包含做个动作，选择其中的步行动作
// const clipAction = mixer.clipAction(gltf.animations[12]);
// clipAction.play(); //播放动画
//休息动作
const IdleAction = mixer.clipAction(gltf.animations[4]);
//步行动作
const WalkAction = mixer.clipAction(gltf.animations[12]);
IdleAction.play();
WalkAction.play();
IdleAction.weight = 1.0;//默认休息状态
WalkAction.weight = 0.0;

function changeAction(name){
  if (name=='Idle'){
      IdleAction.weight = 1.0;//休息状态
      WalkAction.weight = 0.0;
  }else if (name == 'Walk') {
      IdleAction.weight = 0.0;
      WalkAction.weight = 1.0;//步行状态
  } 
}



export {model,mixer,player, changeAction};
